<template>
  <div class="app-container">
    <div class="filter-container">
      <el-date-picker v-model="listQuery.date" style="width:150px" format="yyyy-MM-dd" type="datetime" placeholder="开始日期" />
      <el-date-picker v-model="listQuery.date_end" style="width:150px" format="yyyy-MM-dd" type="datetime" placeholder="结束日期" />
      <el-input v-model="listQuery.real_name" placeholder="客户姓名" style="width: 150px;margin-top:8px" class="filter-item" @keyup.enter.native="handleFilter" />
      <company ref="companys" />
      <el-select v-model="listQuery.dataresult" placeholder="资料情况" class="filter-item" style="width:150px;margin-top:6px">
        <el-option label="资料情况" value="" />
        <el-option label="完成" value="1" />
        <el-option label="部分" value="2" />
        <el-option label="未收到" value="3" />
      </el-select>
      <el-select v-model="listQuery.keyresult" placeholder="钥匙情况" class="filter-item" style="width:150px;margin-top:6px">
        <el-option label="钥匙情况" value="" />
        <el-option label="已收到" value="1" />
        <el-option label="未收到" value="2" />
      </el-select>

      <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" style="margin-top:8px" @click="handleFilter">查询</el-button>
      <excel />
    </div>

    <el-table :key="tableKey" v-loading="listLoading" :data="list" size="mini" border fit highlight-current-row style="width: 100%;">
      <el-table-column label="操作" align="center" width="200" class-name="small-padding fixed-width">
        <template slot-scope="{row,$index}">

          <el-button type="primary" size="mini" @click="create(row.order_id)">
            录入
          </el-button>
          <el-button type="primary" size="mini" @click="record(row.order_id)">
            日志
          </el-button>

        </template>
      </el-table-column>

      <el-table-column label="门店" align="center" width="150">
        <template slot-scope="{row}">
          <span>{{ row.c_name }}</span>
        </template>
      </el-table-column>

      <el-table-column label="客户姓名" align="center" width="150">
        <template slot-scope="{row}">
          <span>{{ row.real_name }}</span>
        </template>
      </el-table-column>
      <el-table-column label="完成时间" align="center" width="100">
        <template slot-scope="{row}">
          <span>{{ row.complate_time }}</span>
        </template>
      </el-table-column>
      <el-table-column label="编号" align="center" width="120">
        <template slot-scope="{row}">
          <span>{{ row.order_contract_num }}</span>
        </template>
      </el-table-column>
      <el-table-column label="车牌" align="center" width="120">
        <template slot-scope="{row}">
          <span>{{ row.plate_no }}</span>
        </template>
      </el-table-column>
      <el-table-column label="资料验收情况" align="center" width="150">
        <template slot-scope="{row}">
          <span>{{ row.data_infor }}</span>
        </template>
      </el-table-column>
      <el-table-column label="钥匙情况" align="center" width="150">
        <template slot-scope="{row}">
          <span>{{ row.keys }}</span>
        </template>
      </el-table-column>

      <el-table-column label="资料收到时间" align="center" width="200">
        <template slot-scope="{row}">
          <span>{{ row.record_time }}</span>
        </template>
      </el-table-column>
      <el-table-column label="转存记录" align="center">
        <template slot-scope="{row}">
          <span>{{ row.desc }}</span>
        </template>
      </el-table-column>

    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />

    <el-dialog title="日志" :visible.sync="orderRecordAble" style="width:1500px;margin:auto">
      <el-timeline :reverse="reverse" style="margin-top:20px">
        <el-timeline-item
          v-for="(collect, index) in loglist"
          :key="index"
          :timestamp="collect.record_time"
        >

          <div style="color:#666;font-size:14px">
            <div class="collectcss">记录人员：<span>{{ collect.admin_name }}</span></div>

            <div class="collectcss">类型：<span>{{ collect.type_name }}</span></div>
            <div class="collectcss">情况：<span>{{ collect.result_name }}</span></div>

            <div class="collectcss">
              <div style="float:left">备注：</div>
              <span style="width:80%;outline:none">
                <span v-html="collect.desc" />

              </span>

            </div>

          </div>
        </el-timeline-item>
      </el-timeline>
    </el-dialog>
    <el-dialog title="录入" :visible.sync="createAble" style="width:1000px;margin:auto">
      <el-form ref="dataForm" :model="create_form" label-width="120px">
        <el-form-item label="类型">
          <el-select v-model="create_form.type" placeholder="类型" class="filter-item" multiple style="width:180px;margin-top:8px">
            <el-option key="1" label="资料" value="1" />
            <el-option key="2" label="钥匙" value="2" />
            <el-option key="3" label="转存记录" value="3" />
          </el-select>
        </el-form-item>
        <!-- <el-form-item v-if="create_form.type==1||create_form.type==2" label="情况">
          <el-select v-model="create_form.result" placeholder="情况" class="filter-item" style="width:180px;margin-top:8px">
            <el-option key="1" label="完成" value="1" />
            <el-option key="2" label="部分" value="2" />
          </el-select>
        </el-form-item> -->
        <el-form-item label="时间">
          <el-date-picker v-model="create_form.date" style="width:180px;" format="yyyy-MM-dd" type="datetime" placeholder="合同收入日期" />
        </el-form-item>
        <el-form-item label="备注信息">
          <el-input v-model="create_form.desc" type="area" style="width:180px;" />
        </el-form-item>

      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="doSubmit(4)">确 定</el-button>
      </span>
    </el-dialog>

  </div>
</template>

<script>
import {
  downloadPdf
} from '@/api/order'
import {
  fetchAllList, createOrderDataRecord, orderDataRecordList, orderDataRecordLog, orderDataRecordExcelout
} from '@/api/order'
import {
  getCustomerInfo
} from '@/api/customer'
import { formatDate } from '@/utils/formatDate.js'
import waves from '@/directive/waves' // waves directive
import excel from '@/components/excelout/index.vue'
import {
  getNodes
} from '@/utils'
import Pagination from '@/components/Pagination' // secondary package based on el-pagination
import company from '@/components/company/company.vue'
export default {
  name: 'ComplexTable',
  components: {
    Pagination, company, excel
  },
  directives: {
    waves
  },
  filters: {
   	formatDate(time) {
   	        time = time * 1000
   	        const date = new Date(time)

   	        return formatDate(date, 'yyyy-MM-dd hh:mm:ss')
   	      }
  },
  data() {
    return {
      loglist: [],
      viewerOptions: true,
      orderRecordAble: false,
      order_idd: '',
      createAble: false,

      orderInfo: [],
      nodes: [],
      create_form: {
        rate: 0.0115,
        order_status: '',
        total_money: '',
        total_period: '',
        total_percentage: ''
      },
      che300DataDetail: [],
      tableKey: 0,
      tableRecord: 1,
      list: null,
      recordTotal: 0,
      total: 0,
      listLoading: true,
      listQuery: {
        page: 1,
        limit: 10,
        step: 'sign',
        real_name: '',
        start: '',
        end: '',
        c_id: '',
        is_settle: ''
      },
      rules: {
        order_status: [{
          required: true,
          message: '审核结果必须选择',
          trigger: 'blur'
        }]

      },
      sale: [],
      imagesData: [],
      orderRecord: [],
      customer_info: []
    }
  },
  created() {
    this.cacheQueryFormat()
    this.nodes = getNodes()
    this.is_system = localStorage.getItem('is_system')
    setInterval(() => {
      this.getList()
    }, 120000)
    this.getList()
    // 添加钩子，页面刷新
    window.addEventListener('beforeunload', e => this.beforeunloadFn(e))
  },
  mdestroyed() {
    // 添加钩子，页面刷新
    window.removeEventListener('beforeunload', e => this.beforeunloadFn(e))
  },
  methods: {
    beforeunloadFn(e) {
      // 刷新页面事件
      sessionStorage.removeItem('orderdata')
    },
    cacheQueryFormat() {
      const cacheQuery = sessionStorage.getItem('orderdata')
      if (cacheQuery) {
        this.listQuery = JSON.parse(cacheQuery)
      }
    },
    create(order_id) {
      this.createAble = true
      this.create_form.order_id = order_id
    },
    record(order_id) {
      this.orderRecordAble = true
      this.create_form.order_id = order_id
      orderDataRecordLog(this.create_form).then(response => {
        this.loglist = response.data
      })
    },
    doSubmit() {
      createOrderDataRecord(this.create_form).then(response => {
        this.$notify({
          title: '提示',
          message: '添加成功',
          type: 'success',
          duration: 2000,
          onClose: this.getList()
        })
        this.createAble = false
        this.create_form = {}
      })
    },

    getList() {
      sessionStorage.setItem('orderdata', JSON.stringify(this.listQuery))
      this.listLoading = true
      // this.listQuery.limit = 10;
      orderDataRecordList(this.listQuery).then(response => {
        this.list = response.data.data
        this.total = response.data.total

        setTimeout(() => {
          this.listLoading = false
        }, 0.2 * 1000)
      })
    },
    excelout() {
      this.listLoading = true
      this.listQuery.page = 1
      this.listQuery.limit = this.total
      orderDataRecordExcelout(this.listQuery).then(response => {
        this.listLoading = false
        const filepath = response.data.path
        window.location.href = filepath
      })
    },
    handleFilter() {
      const c_id = this.$refs.companys.$data.listQuery.c_id
      this.listQuery.c_id = c_id
      this.listQuery.page = 1
      this.getList()
    }
  }
}
</script>
<style>
.pray{color:#909399}
  .green{color:#67C23A;cursor: pointer;}
  .yellow{color:#E6A23C}
  .red{color:#F56C6C}
.contractbox{
  height: 40px;
  color: #00b38a;
  line-height: 50px;
  cursor: pointer;
}
.ima_title{
  font-size: 15px;
  height: 30px;
}
.box {
    margin-left: 50px;
    margin-right: 50px;
  }
  .l_title {
    font-size: 14px;
    font-weight: 700;
    margin-top:20px
  }
  .infolist_top {
    margin-top: 10px;

  }
  .infolist {
    color: #333;
    font-size: 13px;
    margin-left: 10px;
    height: 20px;
    border-bottom: 1px solid #eee;
  }

  .infolist_file {
    color: #1890FF;
    font-size: 15px;
    margin-left: 10px;
  }
  .img_box {
    width: 150px;
    height: 150px;
    margin-left: 16px;
    float: left;
    position: relative;
    margin-bottom: 40px;
  }
  .hovers {
    position: absolute;
    top: 155px;
    width: 100%;
    background: #fff;
    color: #333;
    text-align: center;
  }
  .che300table td{
    border-collapse: collapse;
    height: 40px;
  }
  .che300table tr{
    border-bottom: 1px solid #ccc;
  }
  .che300table {
    border-collapse: collapse;
    width: 80%;
    margin-left: 10%;
  }
  .td_title{
    width: 40%;
    text-align: left;
  }
  .td_value{
    text-align: left;
  }
</style>
